package com.example.boke.utils;

import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;

import java.util.UUID;

public class SecurityUtils {
    //    加密
    public String en(String password){
        String salt = UUID.randomUUID().toString().replace("-","");
        String finalpassword = DigestUtils.md5DigestAsHex((password+salt).getBytes());
        return finalpassword;
    }
    //验证密码
    public Boolean verify(String inputpassword,String sqlpassword){
if(!StringUtils.hasLength(inputpassword)){
    return false;
}
if(sqlpassword == null ||sqlpassword.length() != 64 ){
return false;
}
String salt = sqlpassword.substring(0,32);
String finpassword = DigestUtils.md5DigestAsHex((inputpassword+salt).getBytes());
return finpassword.equals(sqlpassword);
    }
}
